var zfgl_app = function(){
	var rhzParam = {
		currPage: 1,
		pageSize: 20
	};
	var ddmxParam = {
		currPage: 1,
		pageSize: 20
	}
	function loadZfgl(){
		var zfglRactive = new Ractive({
			el: ".hp-container",
			template: "#zfgl-template",
			oncomplete: function(){
				loadRhz();
			}
		})
		zfglRactive.on({
			showRhz: function(e){
				$(e.node).siblings().removeClass("active");
				$(e.node).addClass("active");
				loadRhz();
			},
			showDdmx: function(e){
				$(e.node).siblings().removeClass("active");
				$(e.node).addClass("active");
				loadDdmx();
			}
		})
	}
	
	function loadRhz(){
		var rhzRactive = new Ractive({
			el: ".hp-content",
			template: "#rhz-template",
			oncomplete: function(){
				initRhzTable();
			}
		})
		rhzRactive.on({
			search: function(){
				rhzParam.kssj = rhzRactive.get("kssj");
				rhzParam.jssj = rhzRactive.get("jssj");
				initRhzTable();
			}
		})
	}

	function initRhzTable(){
		var title = ["日期", "消费者已支付订单金额" ,"操作"];
		var tds = [{
            name: 'tjrq',
            width: 100,
            innerhtml: function(opts){
            	if(opts.tjrq){
            		return moment(opts.tjrq).format("YYYY-MM-DD")
            	}
            }
        }, {
            name: 'dhjf',
            width: 100
        },{
            name: 'cz',
            width: 100,
            innerhtml: function (opts) {
                var czStr = "";
                czStr += "<a href='javascript:void(0)' class='hp-lpgl-cz'>明细查询</a>"
                return czStr;
            }
        }];
		// 绘制投诉信息列表
        $("#wd-table").wdGrid({
            url: Constants.amUrlPath + "qzzfgl/getQzzfglRhzPagination",
            colNames: title,
            colModel: tds,
            dataType: "GET",
            submitType: "noForm",
            postData: rhzParam,
            checkflg: false,
            pager: "#wd-pager",
            rowList: Constants.page.rowList,
            pagesize: Constants.page.pagesize,
    		lineheight: 50,
        });
	}
	function loadDdmx(){
		var ddmxRactive = new Ractive({
			el: ".hp-content",
			template: "#ddmx-template",
			oncomplete: function(){
				initDdmxTable();
				
				$.ajax({
					type: "get",
					url: Constants.amUrlPath+"common/getCodeListByCodeClass?codeClass=DHZT",
					success: function(data){
						store.set("DDZT", JSON.stringify(data));
						selecttextInfo();
					}
				})
			}
		})
		ddmxRactive.on({
			search: function(){
				ddmxParam.tgfzh = ddmxRactive.get("tgfzh");
				ddmxParam.tgfmc = ddmxRactive.get("tgfmc");
				ddmxParam.zt = getWDCode("zfgl_DDZT") ? getWDCode("zfgl_DDZT") : "";
				ddmxParam.kssj = ddmxRactive.get("kssj");
				ddmxParam.jssj = ddmxRactive.get("jssj");
				initDdmxTable();
			}
		})
	}
	
	function initDdmxTable(){
		var title = ["订单编号", "交易时间" ,"订单类别", "提供方账号", "提供方名称", "名称", "价格（积分）", "购买方名称", "订单状态"];
		var tds = [{
            name: 'id',
            width: 110
        },{
            name: 'dhsj',
            width: 150,
            innerhtml: function(opts){
            	if(opts.dhsj){
            		return moment(opts.tjrq).format("YYYY-MM-DD HH:mm")
            	}
            }
        }, {
            name: 'dhlbDesc',
            width: 90
        }, {
            name: 'tgfzh',
            width: 100
        }, {
            name: 'tgfmc',
            width: 90
        }, {
            name: 'lpmc',
            width: 110
        }, {
            name: 'jf',
            width: 105
        }, {
            name: 'dhrnc',
            width: 105
        },{
            name: 'dhztDesc',
            width: 100
        }];
		// 绘制投诉信息列表
        $("#wd-table").wdGrid({
            url: Constants.amUrlPath + "qzzfgl/getQzzfglDdmxPagination",
            colNames: title,
            colModel: tds,
            dataType: "GET",
            submitType: "noForm",
            postData: ddmxParam,
            checkflg: false,
            pager: "#wd-pager",
            rowList: Constants.page.rowList,
            pagesize: Constants.page.pagesize,
    		lineheight: 50,
        });
	}
	
	return {
		init: function(){
			loadZfgl();
		}
	}
}();
$(document).ready(zfgl_app.init);